<!--# layout("/layout/weui.html",{}){  #-->
<header class='demos-header'>
	<h1 class="demos-title">绑定账户</h1>
</header>

<div class="weui_cells weui_cells_form">
	<div class="weui_cell weui_vcode">
		<div class="weui_cell_hd">
			<label class="weui_label">用户token</label>
		</div>
		<div class="weui_cell_bd weui_cell_primary">
			<input class="weui_input" type="number" placeholder="请输入用户token" readonly="readonly">
		</div>
		<div class="weui_cell_ft">
			<a href="javascript:;" class="weui_btn weui_btn_primary" id="scan">扫一扫</a>
		</div>
	</div>
</div>
<script type="text/javascript">
<!--
wx.ready(function () {
    $('#scan').on('click', function () {
        wx.scanQRCode({
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                $('.weui_input').val(result);
                $.post('${base!}/qa/bind', {
                    token: result
                }, function (result) {
                    if (result.operationState == 'SUCCESS') {
                        layer.msg('绑定成功!', function () {
                            location.href = '${base!}/qa/me';
                        });
                    } else {
                        layer.msg(result.data.reason);
                    }
                }, 'json')
            }
        });
    });
})
//-->
</script>
<!--# } #-->